<h1 class="crayons-title mb-3">Tags</h1>

<div class="flex items-center mb-6">
  <div class="crayons-tabs">
    <div>
      <%= link_to "All", admin_tags_path("q[supported_not_null]": "true"), class: "crayons-tabs__item #{'crayons-tabs__item--current' if params.dig(:q, :supported_not_null)}", "aria-label": "All Tags", data: { text: "All" } %>
    </div>
    <div>
      <%= link_to "Supported", admin_tags_path("q[supported_eq": "true"), class: "crayons-tabs__item #{'crayons-tabs__item--current' if params.dig(:q, :supported_eq) == 'true'}", "aria-label": "Supported Tags", data: { text: "Supported" } %>
    </div>
    <div>
      <%= link_to "Unsupported", admin_tags_path("q[supported_eq": "false"), class: "crayons-tabs__item #{'crayons-tabs__item--current' if params.dig(:q, :supported_eq) == 'false'}", "aria-label": "Unsupported Tags", data: { text: "Unsupported" } %>
    </div>
  </div>

  <div class="m-auto">
    <%= search_form_for(@q, url: admin_tags_path, class: "inline-flex") do |f| %>
      <%= f.search_field(:name_cont, aria: { label: "Search" }, class: "crayons-textfield") %>
      <% if params.dig(:q, :supported_eq) %>
        <%= f.hidden_field(:supported_eq) %>
      <% else %>
        <%= f.hidden_field(:supported_not_null) %>
      <% end %>
      <%= f.submit "Search", class: "crayons-btn ml-2" %>
    <% end %>
  </div>

  <div class="justify-end ml-auto">
    <%= link_to "Make A Tag", new_admin_tag_path, class: "crayons-btn" %>
  </div>
</div>

<%= paginate @tags %>

<table class="crayons-table" width="100%">
  <thead>
    <tr>
      <th scope="col"><%= sort_link(@q, :name, { aria: { label: "Sort by Name" } }) %></th>
      <th scope="col"><%= sort_link(@q, :id, { aria: { label: "Sort by ID" } }) %></th>
      <th scope="col"><%= sort_link(@q, :alias_for, { aria: { label: "Sort by Alias For" } }) %></th>
      <th scope="col"><%= sort_link(@q, :taggings_count, { aria: { label: "Sort by Taggings Count" } }) %></th>
      <th scope="col">Is Moderated?</th>
    </tr>
  </thead>
  <tbody class="crayons-card">
    <% @tags.each do |tag| %>
      <tr>
        <td><%= link_to tag.name, edit_admin_tag_path(tag.id), aria: { label: "#{tag.name} tag" } %></td>
        <td><%= tag.id %></td>
        <td><%= tag.alias_for %></td>
        <td><%= tag.taggings_count %></td>
        <td><%= tag.tag_moderator_ids.any? %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<%= paginate @tags %>
